package HUZ;

import java.util.*;

public class Test {
    public static void main(String[] args) {
//        System.out.println(mySqrt(34));
//        System.out.println(mySqrt(55));
//        Map<String,String> map=new HashMap<>();
//        Set<Integer>set=new TreeSet<>();
//        set.add(1);
//        set.add(2);
//        set.add(3);
//        set.add(6);
//        set.add(77);
//        Integer[] objects = (Integer[]) set.toArray();
//        Iterator<Integer> iterator = set.iterator();
//        while(iterator.hasNext()){
//            System.out.print(iterator.next()+" ");
//        }
//
//        PriorityQueue<String> queue=new PriorityQueue();

        int[]array=new int[]{1,2,1,4,8,5,4,};
        int i = singleNumber(array);
        System.out.println(i);
    }

    public static int singleNumber(int[] nums) {
        if(nums.length==1)return nums[0];
        TreeSet<Integer>treeSet=new TreeSet<>();
        for(int i=0;i<nums.length;i++){
            if(treeSet.contains(nums[i])){
                treeSet.remove(nums[i]);
            }else{
                treeSet.add(nums[i]);
            }
        }
        System.out.println(treeSet);
        System.out.println("==================");
        System.out.println("第一："+treeSet.first());
        System.out.println("最后："+treeSet.last());
        System.out.println("相对于第大："+treeSet.higher(5));
        System.out.println("相对于第小："+treeSet.lower(3));
        treeSet.pollFirst();
        System.out.println("==================");
        System.out.println(treeSet);
//        System.out.println("第一："+treeSet.);

        return 11;
    }

    public static int mySqrt(int x) {
        Double index=x*1.0/2;
        while(index*index>x){
            index/=2;
        }
        int end=(int)Math.round(index);
        return end;
    }
}

class A implements Comparator<Integer> {

    @Override
    public int compare(Integer o1, Integer o2) {
        return 0;
    }
}
